package com.kiryaka
{
	import com.kiryaka.event.EventDispatcherBase;
	import com.kiryaka.images.icon.IconManager;
	import com.kiryaka.manager.DirDataManager;
	
	import flash.events.Event;
	import flash.xml.XMLNode;
	
	import mx.controls.Alert;
	import mx.controls.Tree;
	import mx.core.FlexGlobals;
	import mx.utils.XMLUtil;

	public class FFM extends EventDispatcherBase
	{
		private static var _instance:FFM = new FFM();
		private var iconManager:IconManager = new IconManager();
		
		private var dirData:DirDataManager = new DirDataManager();
		public function FFM()
		{
			checkInstance();
			super();
		}
		private function checkInstance():void{
			if (_instance != null)
				throw new Error("Singleton can only be accessed through Singleton.instance");
		}
		public static function getInstance():FFM
		{
			if (_instance == null) _instance = new FFM();
			return _instance;
		}
		public static function destroyInstance():void{
			_instance = null;
		}
		
		public function getDirXmlList():XMLList{
			return dirData.getXml();
		}
		
		public function changeDirectory(event:Event):void{
			var selectedNode:XML = Tree(event.target).selectedItem as XML;
			FlexGlobals.topLevelApplication.path.text = dirData.getPath(selectedNode, "");
		}
		public function getSmallIconByType(type:String):Class{
			return iconManager.getSmallIconByType(type);
		}
	}
}